from neo4j import GraphDatabase

uri = 'bolt://localhost:7687'
username = 'neo4j'
password = '12345678'

driver = GraphDatabase.driver(uri=uri, auth=(username,password))

# # 创建语句
# summary = driver.execute_query(
#     """
#         CREATE (a:Person {name: $name})
#         CREATE (b:Person {name: $friendName})
#         CREATE (a)-[:KNOWS]->(b)
#     """,
#     name='Alice', friendName='David', 
#     database_='neo4j',
# ).summary

# print("Created {nodes_created} nodes in {time} ms.".format(
#     nodes_created=summary.counters.nodes_created,
#     time=summary.result_available_after
# ))

# 查询语句
# 圆括号用于表示 (:Nodes) ， -[:ARROWS]→ 表示 (:Nodes) 之间的关系。使用此查询语法，您可以在图上执行创建、读取、更新或删除 (CRUD) 操作。
records, summary, keys = driver.execute_query("""
    MATCH (p:Person)-[:KNOWS]->(:Person)
    RETURN p.name AS name
    """,
    database_="neo4j",
)

# Loop through results and do something with them
for record in records:
    print(record.data())  # obtain record as dict

# Summary information
print("The query `{query}` returned {records_count} records in {time} ms.".format(
    query=summary.query, records_count=len(records),
    time=summary.result_available_after
))